////////////////////////////////
//  GOD ENGINE PROTOTYPE AI  //
//////////////////////////////
/*##############################
# Version:      1.0
# GE required:  0.9b
#
# Description:  Prototype AI using the God Engine API.
#
# Credits:      Godplex
#               Daxter (for original idea and a bit of his code)
#
# Final Notes:  This is not a "good" AI, in that it probably won't be
#               fun to play against. For example; a good, fun AI probably
#               wouldn't construct every building in the town. A good AI
#               would probably behave more strategically, or role-play.
#               The goal of this AI is to simply test the functionality of
#               God Engine, so that's all it should be expected to do. That
#               being said, I hope you like what you see.
#
# Features:     - Gathers resources based on desire
#               ^- Will water fields if necessary
#               ^- Throws trees and ore rocks like a badass (BROKEN, DISABLED)
#               - Puts out fires
#               - Regenerates mana based on town population
#               - Constructs new buildings
#               - (Disabled) Repairs damaged buildings
#               - Maintains an exact number of each disciple type
#
#
# Dependencies: GodEngine.txt and GodEngineH.txt must be included
#               and in the right order for project to build. Also
#               now requires Build Costs.txt
#
# File Order:   Constance.txt (Required for now, won't be required later)
#               Build Costs.txt
#               GodEngineH.txt
#               GodEngine.txt
#               GE Bimbo.txt
#               
##############################*/
/*
###      CONVENTIONS USED      ###
# - Public members prefix:  bim
#  ^- ARE for use outside THIS file
# - Private members prefix: bim_
#  ^- ARE NOT for use outside THIS file
# - PascalCase params, camelCase locals, prefix globals, BIM_CAPS_AND_PREFIX global-constants & enums
#  ^- Reference params prefix with "r" (ex. rMyReferenceParam)
#  ^- Non-reference params must be stored in local variable of same name
#       but different casing (ex. myByValParam = MyByValParam)
# - Methods return values via reference paramaters with the prefix o
#  ^- (ex. geMyMethod(oMethodOutput))
#  ^- DOES NOT WORK, need to figure out how params are actually passed
#
##############################
*/
// Global Constants
global bim_ResourceGatherRadius = 500.0
global bim_MinDesireToStartResource = 0.6
global bim_MaxDesireToStopResource = 0.1
global bim_ManaRatePerAdult = 0.5
global bim_MaxBuiltToGodBuild = 0.5
global bim_DamageToFirefight = 0.9

// Number of Disciples
global bim_MaleBreeders = 2
global bim_NumDiscipleOther = 4

// Script Definitions
define script bimNewBimbo(rTown)
define script bim_BimboLoop(GodHandle,rTown)
define script bim_SatisfyWoodDesire(GodHandle,rTown)
define script bim_SatisfyFoodDesire(GodHandle,rTown)
define script bim_SatisfyOreDesire(GodHandle,rTown)
define script bim_BuildNewBuilding(GodHandle,rTown)
define script bim_Firefight(GodHandle,rTown)
define script bim_Disciples(GodHandle,rTown)


begin script bimNewBimbo(rTown)
	godHandle = -1
start
	// Instantiates a new AI instance
	// run script geGetNewGodHandle(rTown,godHandle)
	
	run script geGetNewGodHandle(rTown)
	godHandle = geReturnVal
	run script geUnlockReturn
	
	if godHandle > -1 // make sure godHandle is valid
		run background script bim_BimboLoop(godHandle,rTown)
	end if
end script bimNewBimbo


begin script bim_BimboLoop(GodHandle,rTown)
	godHandle = GodHandle
	buildingUnderConstruction = 0
	townDesire = 0.0
	manaRate = 0
start
	if godHandle > -1 // make sure godHandle is valid
		while 1 == 1
		
			// Adjust mana rate
			manaRate = (adult size of rTown * bim_ManaRatePerAdult)
			run script geSetManaPerSecond(godHandle,manaRate)
		
			// Do I need to resource?
			townDesire = get rTown desire TOWN_DESIRE_FOR_FOOD
			if townDesire > bim_MinDesireToStartResource
				run script bim_SatisfyFoodDesire(godHandle,rTown)
			end if
			townDesire = get rTown desire TOWN_DESIRE_FOR_WOOD
			if townDesire > bim_MinDesireToStartResource
				run script bim_SatisfyWoodDesire(godHandle,rTown)
			end if
			townDesire = get rTown desire TOWN_DESIRE_FOR_ORE
			if townDesire > bim_MinDesireToStartResource
				run script bim_SatisfyOreDesire(godHandle,rTown)
			end if
			
			// Are there any new buildings to build?
			// (May go mad if there is not enough resources anywhere, haven't tested.)
			run script bim_BuildNewBuilding(godHandle,rTown)
			
			// Are any of my structures on fire? (Repair code has been commented out)
			// (Will no longer repair because repaired buildings look weird)
			run script bim_Firefight(godHandle,rTown)
			
			// Are there enough of each disciple type?
			run script bim_Disciples(godHandle,rTown)

		end while
	end if
end script bim_BimboLoop

// NOTE: GOD WILL NOT WATER FORESTS
begin script bim_SatisfyWoodDesire(GodHandle,rTown)
	godHandle = GodHandle
	myStorehouse = 0
	myTree = get SCRIPT_OBJECT_TYPE_TREE at {rTown} radius bim_ResourceGatherRadius
	townDesire = get rTown desire TOWN_DESIRE_FOR_WOOD
start
	myStorehouse = get building ABODE_NUMBER_STORAGE_PIT in rTown min built 1.0
	if myStorehouse exists
		while townDesire >= bim_MaxDesireToStopResource and SCRIPT_OBJECT_PROPERTY_TYPE_BUILT_PERCENTAGE of myStorehouse >= 1.0 and myTree exists
			// run script geThrowObjectAtObject(godHandle,myTree,myStorehouse)
			run script gePickupResource(godHandle,myTree,GE_HT_WOOD,-1)
			run script geDropInStorehouse(godHandle,myStorehouse,-1)
			townDesire = get rTown desire TOWN_DESIRE_FOR_WOOD
			myTree = get SCRIPT_OBJECT_TYPE_TREE at {rTown} radius bim_ResourceGatherRadius
		end while
	end if
end script bim_SatisfyWoodDesire

begin script bim_SatisfyOreDesire(GodHandle,rTown)
	godHandle = GodHandle
	myStorehouse = 0
	myOreRock = get SCRIPT_OBJECT_TYPE_ORE_ROCK at {rTown} radius bim_ResourceGatherRadius
	townDesire = get rTown desire TOWN_DESIRE_FOR_ORE
start
	myStorehouse = get building ABODE_NUMBER_STORAGE_PIT in rTown min built 1.0
	if myStorehouse exists
		while townDesire >= bim_MaxDesireToStopResource and SCRIPT_OBJECT_PROPERTY_TYPE_BUILT_PERCENTAGE of myStorehouse >= 1.0 and myOreRock exists
			// run script geThrowObjectAtObject(godHandle,myOreRock,myStorehouse)
			run script gePickupResource(godHandle,myOreRock,GE_HT_ORE,-1)
			run script geDropInStorehouse(godHandle,myStorehouse,-1)
			townDesire = get rTown desire TOWN_DESIRE_FOR_ORE
			myOreRock = get SCRIPT_OBJECT_TYPE_ORE_ROCK at {rTown} radius bim_ResourceGatherRadius
		end while
	end if
end script bim_SatisfyOreDesire

// Currently only gathers from 1 field
begin script bim_SatisfyFoodDesire(GodHandle,rTown)
	godHandle = GodHandle
	myStorehouse = 0
	myField = get building ABODE_NUMBER_FIELD in rTown min built 1.0
	foodInField = 0
	townDesire = get rTown desire TOWN_DESIRE_FOR_FOOD
	currentMana = 0
	waterThrows = 0
start
	myStorehouse = get building ABODE_NUMBER_STORAGE_PIT in rTown min built 1.0
	if myStorehouse exists
		while townDesire >= bim_MaxDesireToStopResource and SCRIPT_OBJECT_PROPERTY_TYPE_BUILT_PERCENTAGE of myStorehouse >= 1.0 and myField exists
			foodInField = get resource RESOURCE_TYPE_FOOD in myField
			if foodInField < 600 // then try to water
				run script geGetMana(godHandle)
				currentMana = geReturnVal
				run script geUnlockReturn
				
				waterThrows = currentMana / geManaCostWater
				if waterThrows > 3 // Max times it will water (make global var?)
					waterThrows = 3
				end if
				while waterThrows > 0
					run script geThrowMiracle(godHandle, GE_MIRACLE_TYPE_WATER, myField)
					waterThrows -= 1
					wait 3 seconds
				end while
			end if
			
			run script gePickupResource(godHandle,myField,GE_HT_FOOD,-1)
			run script geDropInStorehouse(godHandle,myStorehouse,-1)
			townDesire = get rTown desire TOWN_DESIRE_FOR_FOOD
		end while
	end if
end script bim_SatisfyFoodDesire


begin script bim_BuildNewBuilding(GodHandle,rTown)
	godHandle = GodHandle
	buildingUnderConstruction = 0
	isThereConstruction = GE_FALSE
	currentMana = 0
start
	// Find out if/which unconstructed building exists (isn't there a way to iterate through game consts??)
	buildingUnderConstruction = get building ABODE_NUMBER_A in rTown max built bim_MaxBuiltToGodBuild
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_B in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_C in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_D in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_E in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_SKYSCRAPER in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_ALTAR in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_STORAGE_PIT in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_CRECHE in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_SHRINE in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_TEMPLE in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_PUB in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_TOWN_CENTRE in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_CREATURE_PEN in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_MELEE_ARMOURY in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_RANGED_ARMOURY in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_WORKSHOP in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_STUDY in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_UNIVERSITY in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_PRISON in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_SMELTER in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_GRANARY in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_LUMBERMILL in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_MARKET_POT in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_MARKET_STATUE in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_MARKET_PLANT in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_AMPITHEATRE in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_GRAVEYARD in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_OLD_PERSONS_HOME in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_BATHHOUSE in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_WALLTOWER_TECH0 in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_WALLTOWER_TECH1 in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_GATEHOUSE in rTown max built bim_MaxBuiltToGodBuild
	end if
	if not buildingUnderConstruction exists
		buildingUnderConstruction = get building ABODE_NUMBER_GATEHOUSE_F in rTown max built bim_MaxBuiltToGodBuild
	end if
	

	if buildingUnderConstruction exists
		// This will probably never be true, but just in case
		if buildingUnderConstruction on fire
			run script geGetMana(godHandle)
			currentMana = geReturnVal
			run script geUnlockReturn
			while buildingUnderConstruction exists and buildingUnderConstruction on fire and geManaCostWater <= currentMana
				run script geThrowMiracle(godHandle, GE_MIRACLE_TYPE_WATER, buildingUnderConstruction)
				currentMana -= geManaCostWater
			end while
		end if
		run script geGodBuild(godHandle,buildingUnderConstruction,bim_ResourceGatherRadius)
		buildingUnderConstruction = 0
	end if
end script bim_BuildNewBuilding


begin script bim_Firefight(GodHandle,rTown)
	godHandle = GodHandle
	damagedBuilding = 0
	isThereConstruction = GE_FALSE
	currentMana = 0
start
	damagedBuilding = get random abode of type ABODE_NUMBER_A in town rTown
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_B in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_C in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_D in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_E in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_SKYSCRAPER in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_ALTAR in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_STORAGE_PIT in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_CRECHE in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_SHRINE in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_TEMPLE in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_PUB in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_TOWN_CENTRE in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_CREATURE_PEN in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_MELEE_ARMOURY in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_RANGED_ARMOURY in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_WORKSHOP in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_STUDY in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_UNIVERSITY in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_PRISON in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_SMELTER in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_GRANARY in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_LUMBERMILL in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_MARKET_POT in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_MARKET_STATUE in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_MARKET_PLANT in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_AMPITHEATRE in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_GRAVEYARD in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_OLD_PERSONS_HOME in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_BATHHOUSE in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_WALLTOWER_TECH0 in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_WALLTOWER_TECH1 in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_GATEHOUSE in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = get random abode of type ABODE_NUMBER_GATEHOUSE_F in town rTown
	end if
	if not SCRIPT_OBJECT_PROPERTY_TYPE_HEALTH of damagedBuilding <= bim_DamageToFirefight
		damagedBuilding = 0
	end if

	if damagedBuilding exists
		if damagedBuilding on fire
			run script geGetMana(godHandle)
			currentMana = geReturnVal
			run script geUnlockReturn
			while damagedBuilding exists and damagedBuilding on fire and geManaCostWater <= currentMana
				run script geThrowMiracle(godHandle, GE_MIRACLE_TYPE_WATER, damagedBuilding)
				currentMana -= geManaCostWater
			end while
		end if
		// Disabled repair because, although it works, the repaired buildings look weird...
		// run script geGodBuild(godHandle,damagedBuilding,bim_ResourceGatherRadius)
		damagedBuilding = 0
	end if
end script bim_Firefight


begin script bim_Disciples(GodHandle,rTown)
	godHandle = GodHandle
	numberOfDisciples = 0
start
	numberOfDisciples = get number of disciple VILLAGER_DISCIPLE_FARMER in town rTown
	while numberOfDisciples < bim_NumDiscipleOther // Need more
		run script geCreateDisciple(godHandle,GE_VILLAGER_DISCIPLE_FARMER)
		numberOfDisciples += 1
	end while
	while bim_NumDiscipleOther < numberOfDisciples // Need less
		run script geRemoveDisciple(godHandle,GE_VILLAGER_DISCIPLE_FARMER,bim_ResourceGatherRadius)
		numberOfDisciples -= 1
	end while
	
	numberOfDisciples = get number of disciple VILLAGER_DISCIPLE_FORESTER in town rTown
	while numberOfDisciples < bim_NumDiscipleOther // Need more
		run script geCreateDisciple(godHandle,GE_VILLAGER_DISCIPLE_FORESTER)
		numberOfDisciples += 1
	end while
	while bim_NumDiscipleOther < numberOfDisciples // Need less
		run script geRemoveDisciple(godHandle,GE_VILLAGER_DISCIPLE_FORESTER,bim_ResourceGatherRadius)
		numberOfDisciples -= 1
	end while 
	
	numberOfDisciples = get number of disciple VILLAGER_DISCIPLE_BUILDER in town rTown
	while numberOfDisciples < bim_NumDiscipleOther // Need more
		run script geCreateDisciple(godHandle,GE_VILLAGER_DISCIPLE_BUILDER)
		numberOfDisciples += 1
	end while
	while bim_NumDiscipleOther < numberOfDisciples // Need less
		run script geRemoveDisciple(godHandle,GE_VILLAGER_DISCIPLE_BUILDER,bim_ResourceGatherRadius)
		numberOfDisciples -= 1
	end while 
	
	numberOfDisciples = get number of disciple VILLAGER_DISCIPLE_BREEDER in town rTown
	while numberOfDisciples < bim_MaleBreeders // Need more
		run script geCreateDisciple(godHandle,GE_VILLAGER_DISCIPLE_BREEDER)
		numberOfDisciples += 1
	end while
	while bim_MaleBreeders < numberOfDisciples // Need less
		run script geRemoveDisciple(godHandle,GE_VILLAGER_DISCIPLE_BREEDER,bim_ResourceGatherRadius)
		numberOfDisciples -= 1
	end while 
	
	numberOfDisciples = get number of disciple VILLAGER_DISCIPLE_WORSHIP in town rTown
	while numberOfDisciples < bim_NumDiscipleOther // Need more
		run script geCreateDisciple(godHandle,GE_VILLAGER_DISCIPLE_WORSHIP)
		numberOfDisciples += 1
	end while
	while bim_NumDiscipleOther < numberOfDisciples // Need less
		run script geRemoveDisciple(godHandle,GE_VILLAGER_DISCIPLE_WORSHIP,bim_ResourceGatherRadius)
		numberOfDisciples -= 1
	end while 
	
	numberOfDisciples = get number of disciple VILLAGER_DISCIPLE_MINER in town rTown
	while numberOfDisciples < bim_NumDiscipleOther // Need more
		run script geCreateDisciple(godHandle,GE_VILLAGER_DISCIPLE_MINER)
		numberOfDisciples += 1
	end while
	while bim_NumDiscipleOther < numberOfDisciples // Need less
		run script geRemoveDisciple(godHandle,GE_VILLAGER_DISCIPLE_MINER,bim_ResourceGatherRadius)
		numberOfDisciples -= 1
	end while
	
	numberOfDisciples = get number of disciple VILLAGER_DISCIPLE_REFINER in town rTown
	while numberOfDisciples < bim_NumDiscipleOther // Need more
		run script geCreateDisciple(godHandle,GE_VILLAGER_DISCIPLE_REFINER)
		numberOfDisciples += 1
	end while
	while bim_NumDiscipleOther < numberOfDisciples // Need less
		run script geRemoveDisciple(godHandle,GE_VILLAGER_DISCIPLE_REFINER,bim_ResourceGatherRadius)
		numberOfDisciples -= 1
	end while 
end script bim_Disciples
